/*
 * 	Additional function for tables.html
 *	Written by ThemePixels	
 *	http://themepixels.com/
 *
 *	Copyright (c) 2012 ThemePixels (http://themepixels.com)
 *	
 *	Built for Amanda Premium Responsive Admin Template
 *  http://themeforest.net/category/site-templates/admin-templates
 */

jQuery(document).ready(function(){
	jQuery('#postTable').dataTable({
		"sPaginationType": "full_numbers",
		"oLanguage": {
			"sLengthMenu": "每页显示 _MENU_ 条记录",
			"sZeroRecords": "抱歉， 没有找到",
			"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
			"sInfoEmpty": "没有数据",
			"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
			"sSearch":"全文搜索:",
			"oPaginate": {
			"sFirst": "首页",
			"sPrevious": "前一页",
			"sNext": "后一页",
			"sLast": "尾页",
			},
			"sZeroRecords": "没有检索到数据",
			"sProcessing": "<img src='./loading.gif' />"
		}
	});
	
	jQuery('#addPostBtn').click(function(){
		jQuery('#post_dialog').attr("title","添加部门信息");
		jQuery('input[name="post.postNo"]').parent().parent().hide();
		jQuery('#editPostInfo').attr("action","/post/add");
		jQuery('#editBtn').hide();
		jQuery('#addBtn').show();
		jQuery("#post_dialog").dialog({
			 width:500,
		     modal:true
		});
	});
	
});

function confirmDelete(id, no, name) {
	jConfirm('你确定要删除' + name + '吗?', '删除'+no+'部门', function(r) {
		if(r) {
			jQuery.ajax({
				   type: "post",
				   url: "/post/delete",
				   dataType:"json",
				   data: {postId: id},
				   success: function(data){
					   if(data.flag == true) {
						   	window.location.reload();
						   	jQuery.jGrowl("恭喜您，删除岗位成功！");
					   }else {
						   jQuery.jGrowl("很抱歉，删除岗位失败！请先删除相关员工信息。");
					   }
				   },
					error:function(e) {  
						jQuery.jGrowl("很抱歉，删除部门失败！");
			        }
				 });
		}
	});
	return false;
};

function showEditDialog(object,id, deptId){
	jQuery('#post_dialog').attr("title","修改部门信息");
	jQuery('input[name="post.postNo"]').parent().parent().show();
	jQuery('#editPostInfo').attr("action","/post/edit");
	jQuery('#editBtn').show();
	jQuery('#addBtn').hide();
	var button = jQuery(object);
	var td=button.parent("td");
	var data = [];
	td.siblings().each(function(){
		data.push(jQuery(this).html());
	});
	jQuery("#postId").val(id);
	jQuery("#postNo").val(data[1]);
	jQuery("#postName").val(data[2]);
	jQuery("#deptId").val(deptId);
	jQuery("#postDescription").val(data[4]);
	jQuery("#post_dialog").dialog({
		 width:500,
	     modal:true
	});
};